package transform

import (
	"apidoc2entity/model"
)

// 数据分组拼装
func MapToStruct(fields []model.BuilderField) <-chan *model.BuilderStruct {
	smap := make(map[string]*model.BuilderStruct)
	out := make(chan *model.BuilderStruct)
	for _, f := range fields {
		_, ok := smap[f.StructCode]
		if !ok {
			cur := &model.BuilderStruct{}
			cur.StructCode = f.StructCode
			cur.PackageCode = f.PackageCode
			cur.StructName = f.StructName
			smap[f.StructCode] = cur
		}
		smap[f.StructCode].BFields = append(smap[f.StructCode].BFields, f)
	}
	go func() {
		defer close(out)
		for _, v := range smap {
			out <- v
		}
	}()
	return out
}
